﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace TestCase.ICollectionViewFiltering.WPF
{

    
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        List<Model> _source;
        //ICollectionView _collectionView;
        public MainWindow()
        {
            InitializeComponent();



            _source = new List<Model>
            {
                new Model{Data = "Item 1", IsVisible = true},
                new Model{Data = "Item 2", IsVisible = false},
                new Model{Data = "Item 3", IsVisible = true},
                new Model{Data = "Item 4", IsVisible = false},
                new Model{Data = "Item 5", IsVisible = true},
                new Model{Data = "Item 6", IsVisible = false},
                new Model{Data = "Item 7", IsVisible = true},
                new Model{Data = "Item 8", IsVisible = false},
                new Model{Data = "Item 9", IsVisible = true},
                new Model{Data = "Item 10", IsVisible = false},
            };


            //_collectionView = new CollectionView(list);
            this.itemsControl2D.ItemsSource = _source;
            this.itemsControl3D.ItemsSource = _source;
            this.lstBox.ItemsSource = _source;

        }

        private void OnApplyFilter(object sender, RoutedEventArgs e)
        {
            var cv = CollectionViewSource.GetDefaultView(_source);
            cv.Filter = o => ((Model)o).IsVisible;
        }

        private void OnRemoveFilter(object sender, RoutedEventArgs e)
        {
            var cv = CollectionViewSource.GetDefaultView(_source);
            cv.Filter = null;

        }
    }

    public class Model
    {
        public string Data { get; set; }
        public bool IsVisible { get; set; }
    }
}
